<template>
  <!-- 弹出框一 -->

  <vol-box :lazy="true" v-if="model1" v-model="model1" title="库位明细" :width="1200" :height="1500" :padding="5"
    :onModelClose="onModelClose">
    <vol-form ref="editForm" :load-key="false" :formRules="editFormOptions" :formFields="editFormFields"> </vol-form>

    <template #footer>
      <div>
        <!-- <el-button type="primary" plain size="small" @click="callParent">调用生成(父)页面对象</el-button> -->
        <el-button type="primary" size="small" @click="closeModel1">确认</el-button>
        <el-button type="default" size="small" @click="model1 = false">关闭</el-button>
      </div>
    </template>
  </vol-box>
</template>
<script>
import VolBox from '@/components/basic/VolBox.vue'
import VolForm from '@/components/basic/VolForm.vue'

//这里使用的vue2语法，也可以写成vue3语法
export default {
  emits: ['parentCall'],
  components: { 'vol-box': VolBox, VolForm },
  methods: {},
  data() {
    return {
      model1: false,
      model1Rows: [], //弹出框1传入的选中行
      model2: false,
      model2Row: {}, //弹出框2点击的当前行数据
      editFormOptions: [
        [
          { title: '调账数量', required: true, field: 'TakeQty', props:{type:'number'} },
        ],
      ],
      editFormFields: {  },
    }
  },
  methods: {

    openModel1(rows) {
      //弹出框1
      this.model1Rows = rows
      console.log("🚀 ~ openModel1 ~ rows:", rows)
      this.editFormFields.TakeQty = rows.TakeQty
      console.log("🚀 ~ openModel1 ~ this.editFormFields:", this.editFormFields)
      this.model1 = true
    },





    closeModel1() {
      this.model1Rows.TakeQty = Number(this.editFormFields.TakeQty)
      const flag = this.$refs.editForm.validate()
      flag.then(r => {
        if (r) {
          this.http
            .post('/api/Wms_MatStockTaking/updateStocktakingQtyItem', {
              ...this.model1Rows
            })
            .then((r) => {
              this.model1 = false
              this.callParent()
            })
        }
      })


    },
    callParent() {
      this.$emit('parentCall', ($parent) => {
        //$parent就是生成页面的对象，比如可以调用页面刷新，可获取的属性与方法见【生成页面文档】,$parent.xxx直接调用
        //调用刷新
        $parent.search()
        //获取所有选中的行数据
        // $parent.getSelectRows();
      })
    },
    onModelClose() { },
  },
}
</script>
